<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="RestTemplate">
<meta property="og:type" content="article">
<meta property="og:title" content="RestTemplate使用">
<meta property="og:url" content="https://whitestore.top/2020/08/22/note15/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="RestTemplate">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-08-22T11:34:40.000Z">
<meta property="article:modified_time" content="2023-07-16T06:28:09.229Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="RestTemplate日常使用">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://whitestore.top/2020/08/22/note15/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>RestTemplate使用 | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2020/08/22/note15/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          RestTemplate使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-22 19:34:40" itemprop="dateCreated datePublished" datetime="2020-08-22T19:34:40+08:00">2020-08-22</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-07-16 14:28:09" itemprop="dateModified" datetime="2023-07-16T14:28:09+08:00">2023-07-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/SpringBoot/" itemprop="url" rel="index"><span itemprop="name">SpringBoot</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/08/22/note15/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/08/22/note15/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>6.6k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>6 分钟</span>
            </span>
            <div class="post-description">RestTemplate</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="RestTemplate介绍"><a href="#RestTemplate介绍" class="headerlink" title="RestTemplate介绍"></a><code>RestTemplate</code>介绍</h1><h2 id="借鉴"><a href="#借鉴" class="headerlink" title="借鉴"></a>借鉴</h2><p><span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vcG9zdC82ODQ0OTAzODQyMDY1MTU0MDYx" title="https://juejin.im/post/6844903842065154061">https://juejin.im/post/6844903842065154061<i class="fa fa-external-link"></i></span> 掘金</p>
<a id="more"></a>

<h2 id="认识-RestTemplate"><a href="#认识-RestTemplate" class="headerlink" title="认识 RestTemplate"></a>认识 <code>RestTemplate</code></h2><p>简要改过：HTTP请求工具，封装了HttpClient请求的一系列方法</p>
<p>所属：<span class="exturl" data-url="aHR0cDovL3NwcmluZy53ZWI=" title="http://spring.web">spring.web<i class="fa fa-external-link"></i></span> 包 4.1.3 之后</p>
<p><strong>Spring Framework 3.0之后才开始引入</strong></p>
<h2 id="为什么会出现RestTemplate"><a href="#为什么会出现RestTemplate" class="headerlink" title="为什么会出现RestTemplate"></a>为什么会出现<code>RestTemplate</code></h2><ol>
<li>最大的作用就是简化Http请求。</li>
<li>无需自己编写底层</li>
<li>开箱即用</li>
</ol>
<h2 id="Spring-5-0之后的改变"><a href="#Spring-5-0之后的改变" class="headerlink" title="Spring 5.0之后的改变"></a>Spring 5.0之后的改变</h2><p>5.0之后，官方更加推荐应对非阻塞响应式的 HTTP 请求处理类 <code>org.springframework.web.reactive.client.WebClient</code>来处理</p>
<h2 id="一些常用API"><a href="#一些常用API" class="headerlink" title="一些常用API"></a>一些常用API</h2><p>其中多数是单个方法重载实现，这里我主要参考官方文档 <span class="exturl" data-url="aHR0cHM6Ly9kb2NzLnNwcmluZy5pby9zcHJpbmcvZG9jcy81LjEuNi5SRUxFQVNFL3NwcmluZy1mcmFtZXdvcmstcmVmZXJlbmNlL2ludGVncmF0aW9uLmh0bWwjcmVzdC1jbGllbnQtYWNjZXNz" title="https://docs.spring.io/spring/docs/5.1.6.RELEASE/spring-framework-reference/integration.html#rest-client-access">rest-client-access<i class="fa fa-external-link"></i></span> 进行如下分类：</p>
<table>
<thead>
<tr>
<th>方法名</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>getForObject</code></td>
<td>通过 GET 请求获得响应结果</td>
</tr>
<tr>
<td><code>getForEntity</code></td>
<td>通过 GET 请求获取 <code>ResponseEntity</code> 对象，包容有状态码，响应头和响应数据</td>
</tr>
<tr>
<td><code>headForHeaders</code></td>
<td>以 HEAD 请求资源返回所有响应头信息</td>
</tr>
<tr>
<td><code>postForLocation</code></td>
<td>用 POST 请求创建资源，并返回响应数据中响应头的字段 <code>Location</code>的数据</td>
</tr>
<tr>
<td><code>postForObject</code></td>
<td>通过 POST 请求创建资源，获得响应结果</td>
</tr>
<tr>
<td><code>put</code></td>
<td>通过 PUT 方式请求来创建或者更新资源</td>
</tr>
<tr>
<td><code>patchForObject</code></td>
<td>通过 PATH 方式请求来更新资源，并获得响应结果。(JDK <code>HttpURLConnection</code> 不支持 PATH 方式请求，其他 HTTP 客户端库支持)</td>
</tr>
<tr>
<td><code>delete</code></td>
<td>通过 DELETE 方式删除资源</td>
</tr>
<tr>
<td><code>optionsForAllow</code></td>
<td>通过 ALLOW 方式请求来获得资源所允许访问的所有 HTTP 方法，可用看某个请求支持哪些请求方式</td>
</tr>
<tr>
<td><code>exchange</code></td>
<td>更通用版本的请求处理方法，接受一个 <code>RequestEntity</code> 对象，可以设置路径，请求头，请求信息等，最后返回一个 <code>ResponseEntity</code> 实体</td>
</tr>
<tr>
<td><code>execute</code></td>
<td>最通用的执行 HTTP 请求的方法，上面所有方法都是基于 <code>execute</code>的封装，全面控制请求信息，并通过回调接口获得响应数据</td>
</tr>
</tbody></table>
<h2 id="常见用法："><a href="#常见用法：" class="headerlink" title="常见用法："></a>常见用法：</h2><h3 id="GET-请求："><a href="#GET-请求：" class="headerlink" title="GET 请求："></a>GET 请求：</h3><h4 id="使用GET请求获取JSON字符串"><a href="#使用GET请求获取JSON字符串" class="headerlink" title="使用GET请求获取JSON字符串:"></a>使用GET请求获取JSON字符串:</h4><p>我们只需要调用：<code>getForObject</code>即可</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">String forObject &#x3D; build.getForObject(&quot;http:&#x2F;&#x2F;www.baidu.com&quot;, String.class);</span><br><span class="line">.....</span><br></pre></td></tr></table></figure>

<h4 id="使用GET请求获取JSON映射对象："><a href="#使用GET请求获取JSON映射对象：" class="headerlink" title="使用GET请求获取JSON映射对象："></a>使用GET请求获取JSON映射对象：</h4><p>只需要将后面的参数改为 对应实体对象即可</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Product forObject &#x3D; build.getForObject(&quot;http:&#x2F;&#x2F;www.baidu.com&quot;, Product.class);</span><br></pre></td></tr></table></figure>

<h4 id="使用GET请求获取更加详细的Entity对象"><a href="#使用GET请求获取更加详细的Entity对象" class="headerlink" title="使用GET请求获取更加详细的Entity对象"></a>使用GET请求获取更加详细的Entity对象</h4><p>使用<code>getForEntity</code>即可获取更为详细的对象</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ResponseEntity&lt;String&gt; forEntity &#x3D; build.getForEntity(&quot;http:&#x2F;&#x2F;www.baidu.com&quot;, String.class);</span><br></pre></td></tr></table></figure>

<h4 id="构建自定义的请求头："><a href="#构建自定义的请求头：" class="headerlink" title="构建自定义的请求头："></a>构建自定义的请求头：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">MultiValueMap header &#x3D; new LinkedMultiValueMap();</span><br><span class="line">       header.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);</span><br><span class="line">       HttpEntity&lt;Object&gt; requestEntity &#x3D; new HttpEntity&lt;&gt;(header);</span><br></pre></td></tr></table></figure>

<h4 id="构建自定义请求header"><a href="#构建自定义请求header" class="headerlink" title="构建自定义请求header"></a>构建自定义请求header</h4><p>一般使用<code>exchange</code>的相关方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ResponseEntity&lt;String&gt; exchange &#x3D; build.exchange(&quot;http:&#x2F;&#x2F;www.baidu.com&quot;, HttpMethod.GET, requestEntity, String.class);</span><br><span class="line">        System.out.println(&quot;get_product1返回结果：&quot; + exchange);</span><br></pre></td></tr></table></figure>

<h4 id="手动处理请求头以及返回信息"><a href="#手动处理请求头以及返回信息" class="headerlink" title="手动处理请求头以及返回信息"></a>手动处理请求头以及返回信息</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">build.execute(&quot;http:&#x2F;&#x2F;www.baidu.com&quot;, HttpMethod.GET, request -&gt; &#123;</span><br><span class="line">            request.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);</span><br><span class="line">        &#125;, response -&gt; &#123;</span><br><span class="line">            HttpStatus statusCode &#x3D; response.getStatusCode();</span><br><span class="line">            int value &#x3D; statusCode.value();</span><br><span class="line">            System.err.println(&quot;响应code: &#x3D; &quot; + value);</span><br><span class="line">            return value;</span><br><span class="line">        &#125;);</span><br></pre></td></tr></table></figure>

<p>这里有两个比较关键的接口</p>
<p><strong>RequestCallback requestCallback,</strong></p>
<p><strong>ResponseExtractor<T> responseExtractor</strong></p>
<p>可以使用lambada 表达式简化，或者使用匿名内部类</p>
<h4 id="使用带参数的Get请求"><a href="#使用带参数的Get请求" class="headerlink" title="使用带参数的Get请求"></a>使用带参数的Get请求</h4><ol>
<li>首先我们需要定义占位符</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">String url &#x3D;&quot;htttp:&#x2F;&#x2F;localhost:8080?id&#x3D;&#123;id&#125;&quot;</span><br></pre></td></tr></table></figure>

<p>注意{id} 的写法,有点像<code>@PathValiable</code> 的写法</p>
<h5 id="使用动态参数："><a href="#使用动态参数：" class="headerlink" title="使用动态参数："></a>使用动态参数：</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 带参数的GET请求</span><br><span class="line">String url &#x3D; &quot;http:&#x2F;&#x2F;localhost:7474?id&#x3D;&#123;id&#125;&quot;;</span><br><span class="line">build.getForObject(url, String.class, 11);</span><br></pre></td></tr></table></figure>

<h5 id="使用map设置参数"><a href="#使用map设置参数" class="headerlink" title="使用map设置参数"></a>使用map设置参数</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 使用map 设置参数</span><br><span class="line">Map&lt;String, Object&gt; uriVariables &#x3D; new HashMap&lt;&gt;();</span><br><span class="line">uriVariables.put(&quot;id&quot;, 101);</span><br><span class="line">build.getForObject(url, String.class, uriVariables);</span><br></pre></td></tr></table></figure>

<h3 id="POST-请求："><a href="#POST-请求：" class="headerlink" title="POST 请求："></a>POST 请求：</h3><p>Post请求相对GET请求有更多的变化，这里也是列出日常开放比较常用的点</p>
<h4 id="发送-Content-Type-为-application-x-www-form-urlencoded的-POST-请求："><a href="#发送-Content-Type-为-application-x-www-form-urlencoded的-POST-请求：" class="headerlink" title="发送 Content-Type 为 application/x-www-form-urlencoded的 POST 请求："></a>发送 <code>Content-Type</code> 为 <code>application/x-www-form-urlencoded</code>的 POST 请求：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 设置请求头</span><br><span class="line">MultiValueMap multiValueMap &#x3D; new LinkedMultiValueMap();</span><br><span class="line">multiValueMap.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);</span><br><span class="line"></span><br><span class="line">User user &#x3D; new User();</span><br><span class="line">&#x2F;&#x2F;方式二： 将请求参数值以 K&#x3D;V 方式用 &amp; 拼接，发送请求使用</span><br><span class="line">String productStr &#x3D; &quot;id&#x3D;&quot; +  user.getId() + &quot;&amp;name&#x3D;&quot; + user.getName() + &quot;&amp;price&#x3D;&quot; + user.getSalt();</span><br><span class="line">&#x2F;&#x2F; 构建form参数的url</span><br><span class="line">HttpEntity&lt;String&gt; request &#x3D; new HttpEntity&lt;&gt;(productStr, header);</span><br><span class="line">ResponseEntity&lt;String&gt; exchange1 &#x3D; build.exchange(url, HttpMethod.POST, request, String.class);</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 方式3 ，使用map</span><br><span class="line">&#x2F;&#x2F; 构建form参数的url</span><br><span class="line">HttpEntity&lt;String&gt; request &#x3D; new HttpEntity&lt;&gt;(productStr, header);</span><br><span class="line">ResponseEntity&lt;String&gt; exchange1 &#x3D; build.exchange(url, HttpMethod.POST, request, String.class);</span><br><span class="line"></span><br><span class="line">Map&lt;String, Object&gt; stringObjectMap &#x3D; new HashMap&lt;&gt;();</span><br><span class="line">stringObjectMap.put(&quot;test&quot;, &quot;123&quot;);</span><br><span class="line">stringObjectMap.put(&quot;test1&quot;, &quot;123&quot;);</span><br><span class="line">stringObjectMap.put(&quot;test2&quot;, &quot;123&quot;);</span><br><span class="line">HttpEntity httpEntity &#x3D; new HttpEntity&lt;&gt;(stringObjectMap, header);</span><br><span class="line">ResponseEntity exchange2 &#x3D; build.exchange(url, HttpMethod.POST, httpEntity, String.class);</span><br></pre></td></tr></table></figure>

<h4 id="发送-Content-Type-为-application-json-的-POST-请求："><a href="#发送-Content-Type-为-application-json-的-POST-请求：" class="headerlink" title="发送 Content-Type 为 application/json 的 POST 请求："></a>发送 <code>Content-Type</code> 为 <code>application/json</code> 的 POST 请求：</h4><p>只需要将上面的案例当中的:</p>
<p><code>MediaType.APPLICATION_FORM_URLENCODED_VALUE</code>改为：<code>MediaType.APPLICATION_JSON_VALUE</code>即可</p>
<h3 id="DELETE-请求以及PUT请求"><a href="#DELETE-请求以及PUT请求" class="headerlink" title="DELETE 请求以及PUT请求"></a>DELETE 请求以及PUT请求</h3><p>因为都是<code>RestFul</code>的请求，所以简单描述</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">String url &#x3D; &quot;http:&#x2F;&#x2F;localhost:8080&#x2F;product&#x2F;update&quot;;</span><br><span class="line">Map&lt;String, ?&gt; variables &#x3D; new HashMap&lt;&gt;();</span><br><span class="line">MultiValueMap&lt;String, String&gt; header &#x3D; new LinkedMultiValueMap();</span><br><span class="line">header.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED_VALUE));</span><br><span class="line">Product product &#x3D; new Product(101, &quot;iWatch&quot;, BigDecimal.valueOf(2333));</span><br><span class="line">String productStr &#x3D; &quot;id&#x3D;&quot; + product.getId() + &quot;&amp;name&#x3D;&quot; + product.getName() + &quot;&amp;price&#x3D;&quot; + product.getPrice();</span><br><span class="line">HttpEntity&lt;String&gt; request &#x3D; new HttpEntity&lt;&gt;(productStr, header);</span><br><span class="line">restTemplate.put(url, request);</span><br></pre></td></tr></table></figure>

<h3 id="使用restTemplate实现文件上传"><a href="#使用restTemplate实现文件上传" class="headerlink" title="使用restTemplate实现文件上传"></a>使用restTemplate实现文件上传</h3><ol>
<li>需要设置multitype/file 文件请求头</li>
<li>需要设置headaer 以及 body</li>
<li>只能使用post请求</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">String ui &#x3D; &quot;&quot;;</span><br><span class="line">MultiValueMap&lt;String, Object&gt; body &#x3D; new LinkedMultiValueMap&lt;&gt;();</span><br><span class="line">FileSystemResource fileSystemResource &#x3D; new FileSystemResource();</span><br><span class="line">body.add(&quot;file&quot;, fileSystemResource);</span><br><span class="line"></span><br><span class="line">MultiValueMap&lt;String, String&gt; header2 &#x3D; new LinkedMultiValueMap();</span><br><span class="line">header2.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.MULTIPART_FORM_DATA_VALUE));</span><br><span class="line">HttpEntity httpquest &#x3D; new HttpEntity&lt;&gt;(body, header2);</span><br><span class="line">ResponseEntity&lt;String&gt; xxx &#x3D; build.postForEntity(&quot;xxx&quot;, httpquest, String.class);</span><br></pre></td></tr></table></figure>

<h2 id="进阶-RestTemplate"><a href="#进阶-RestTemplate" class="headerlink" title="进阶 RestTemplate"></a>进阶 RestTemplate</h2><h3 id="如何设置RestTempalate的默认底层引擎"><a href="#如何设置RestTempalate的默认底层引擎" class="headerlink" title="如何设置RestTempalate的默认底层引擎"></a>如何设置RestTempalate的默认底层引擎</h3><p>RestTemplate 默认使用的引擎：</p>
<ul>
<li>Apache HttpComponents</li>
<li>Netty</li>
<li>OkHttp</li>
</ul>
<p>一句话概括：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">RestTemplate template &#x3D; new RestTemplate(new HttpComponentsClientHttpRequestFactory());</span><br></pre></td></tr></table></figure>

<h3 id="如何修改RestTemplate-的超时时间"><a href="#如何修改RestTemplate-的超时时间" class="headerlink" title="如何修改RestTemplate 的超时时间"></a>如何修改RestTemplate 的超时时间</h3><p>参考代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">RestTemplate customRestTemplate &#x3D; new RestTemplate(getClientHttpRequestFactory());</span><br><span class="line"></span><br><span class="line">private SimpleClientHttpRequestFactory getClientHttpRequestFactory() &#123;</span><br><span class="line">    SimpleClientHttpRequestFactory clientHttpRequestFactory</span><br><span class="line">            &#x3D; new SimpleClientHttpRequestFactory();</span><br><span class="line">    &#x2F;&#x2F; 连接超时设置 10s</span><br><span class="line">    clientHttpRequestFactory.setConnectTimeout(10_000);</span><br><span class="line"></span><br><span class="line">    &#x2F;&#x2F; 读取超时设置 10s</span><br><span class="line">    clientHttpRequestFactory.setReadTimeout(10_000);</span><br><span class="line">    return clientHttpRequestFactory;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果要调整 <code>HttpComponentsClient</code> 的超时设置，可以参考文章<span class="exturl" data-url="aHR0cHM6Ly9ob3d0b2RvaW5qYXZhLmNvbS9zcHJpbmctYm9vdDIvcmVzdHRlbXBsYXRlLXRpbWVvdXQtZXhhbXBsZS8=" title="https://howtodoinjava.com/spring-boot2/resttemplate-timeout-example/">resttemplate-timeout-example<i class="fa fa-external-link"></i></span> 。当然除了设置超时时间之外，还有更多参数进行定制，这里就不一一列举，可以参考文章 <span class="exturl" data-url="aHR0cHM6Ly9ob3d0b2RvaW5qYXZhLmNvbS9zcHJpbmctcmVzdGZ1bC9yZXN0dGVtcGxhdGUtaHR0cGNsaWVudC1qYXZhLWNvbmZpZy8=" title="https://howtodoinjava.com/spring-restful/resttemplate-httpclient-java-config/">resttemplate-httpclient-java-config<i class="fa fa-external-link"></i></span> 进一步学习。</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p><span class="exturl" data-url="aHR0cHM6Ly93d3cuYmFlbGR1bmcuY29tL3Jlc3QtdGVtcGxhdGU=" title="https://www.baeldung.com/rest-template">www.baeldung.com/rest-templa…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cDovL2Jsb2cuZGlkaXNwYWNlLmNvbS9zcHJpbmctYm9vdC1sZWFybmluZy0yMS0xLTE=" title="http://blog.didispace.com/spring-boot-learning-21-1-1">blog.didispace.com/spring-boot…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly93d3cuYmFlbGR1bmcuY29tL3NwcmluZy1yZXN0LXRlbXBsYXRlLW11bHRpcGFydC11cGxvYWQ=" title="https://www.baeldung.com/spring-rest-template-multipart-upload">www.baeldung.com/spring-rest…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly93d3cuemhpaHUuY29tL3F1ZXN0aW9uLzI4NTU3MTE1" title="https://www.zhihu.com/question/28557115">www.zhihu.com/question/28…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9ob3d0b2RvaW5qYXZhLmNvbS9zcHJpbmctYm9vdDIvcmVzdHRlbXBsYXRlLXRpbWVvdXQtZXhhbXBsZQ==" title="https://howtodoinjava.com/spring-boot2/resttemplate-timeout-example">howtodoinjava.com/spring-boot…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9kb2NzLnNwcmluZy5pby9zcHJpbmcvZG9jcy81LjEuNi5SRUxFQVNFL3NwcmluZy1mcmFtZXdvcmstcmVmZXJlbmNlL2ludGVncmF0aW9uLmh0bWwjcmVzdC1jbGllbnQtYWNjZXNz" title="https://docs.spring.io/spring/docs/5.1.6.RELEASE/spring-framework-reference/integration.html#rest-client-access">docs.spring.io/spring/docs…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly96aC53aWtpcGVkaWEub3JnL3dpa2kv6KGo546w5bGC54q25oCB6L2s5o2i" title="https://zh.wikipedia.org/wiki/表现层状态转换">zh.wikipedia.org/wiki/表现层状态转…<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9kb2NzLnNwcmluZy5pby9zcHJpbmctZnJhbWV3b3JrL2RvY3MvY3VycmVudC9qYXZhZG9jLWFwaS9vcmcvc3ByaW5nZnJhbWV3b3JrL3dlYi9jbGllbnQvUmVzdE9wZXJhdGlvbnMuaHRtbA==" title="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestOperations.html">docs.spring.io/spring-fram…<i class="fa fa-external-link"></i></span></p>
<p>作者：闻人的技术博客 链接：<span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vcG9zdC82ODQ0OTAzODQyMDY1MTU0MDYx" title="https://juejin.im/post/6844903842065154061">https://juejin.im/post/6844903842065154061<i class="fa fa-external-link"></i></span> 来源：掘金 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。</p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2020/08/22/note15/" title="RestTemplate使用">https://whitestore.top/2020/08/22/note15/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/SpringBoot/" rel="tag"># SpringBoot</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/08/22/note13/" rel="prev" title="蓝牙应该怎么选？">
      <i class="fa fa-chevron-left"></i> 蓝牙应该怎么选？
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/08/22/note16/" rel="next" title="显示器怎么选？">
      显示器怎么选？ <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#RestTemplate介绍"><span class="nav-number">1.</span> <span class="nav-text">RestTemplate介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#借鉴"><span class="nav-number">1.1.</span> <span class="nav-text">借鉴</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#认识-RestTemplate"><span class="nav-number">1.2.</span> <span class="nav-text">认识 RestTemplate</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么会出现RestTemplate"><span class="nav-number">1.3.</span> <span class="nav-text">为什么会出现RestTemplate</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Spring-5-0之后的改变"><span class="nav-number">1.4.</span> <span class="nav-text">Spring 5.0之后的改变</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#一些常用API"><span class="nav-number">1.5.</span> <span class="nav-text">一些常用API</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常见用法："><span class="nav-number">1.6.</span> <span class="nav-text">常见用法：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#GET-请求："><span class="nav-number">1.6.1.</span> <span class="nav-text">GET 请求：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用GET请求获取JSON字符串"><span class="nav-number">1.6.1.1.</span> <span class="nav-text">使用GET请求获取JSON字符串:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用GET请求获取JSON映射对象："><span class="nav-number">1.6.1.2.</span> <span class="nav-text">使用GET请求获取JSON映射对象：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用GET请求获取更加详细的Entity对象"><span class="nav-number">1.6.1.3.</span> <span class="nav-text">使用GET请求获取更加详细的Entity对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#构建自定义的请求头："><span class="nav-number">1.6.1.4.</span> <span class="nav-text">构建自定义的请求头：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#构建自定义请求header"><span class="nav-number">1.6.1.5.</span> <span class="nav-text">构建自定义请求header</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#手动处理请求头以及返回信息"><span class="nav-number">1.6.1.6.</span> <span class="nav-text">手动处理请求头以及返回信息</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用带参数的Get请求"><span class="nav-number">1.6.1.7.</span> <span class="nav-text">使用带参数的Get请求</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#使用动态参数："><span class="nav-number">1.6.1.7.1.</span> <span class="nav-text">使用动态参数：</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#使用map设置参数"><span class="nav-number">1.6.1.7.2.</span> <span class="nav-text">使用map设置参数</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#POST-请求："><span class="nav-number">1.6.2.</span> <span class="nav-text">POST 请求：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#发送-Content-Type-为-application-x-www-form-urlencoded的-POST-请求："><span class="nav-number">1.6.2.1.</span> <span class="nav-text">发送 Content-Type 为 application&#x2F;x-www-form-urlencoded的 POST 请求：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#发送-Content-Type-为-application-json-的-POST-请求："><span class="nav-number">1.6.2.2.</span> <span class="nav-text">发送 Content-Type 为 application&#x2F;json 的 POST 请求：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DELETE-请求以及PUT请求"><span class="nav-number">1.6.3.</span> <span class="nav-text">DELETE 请求以及PUT请求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用restTemplate实现文件上传"><span class="nav-number">1.6.4.</span> <span class="nav-text">使用restTemplate实现文件上传</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#进阶-RestTemplate"><span class="nav-number">1.7.</span> <span class="nav-text">进阶 RestTemplate</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#如何设置RestTempalate的默认底层引擎"><span class="nav-number">1.7.1.</span> <span class="nav-text">如何设置RestTempalate的默认底层引擎</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何修改RestTemplate-的超时时间"><span class="nav-number">1.7.2.</span> <span class="nav-text">如何修改RestTemplate 的超时时间</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考资料"><span class="nav-number">1.8.</span> <span class="nav-text">参考资料</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
